package com.rudolfheszele.smsselector.view;

import com.rudolfheszele.smsselector.R;
import com.rudolfheszele.smsselector.controller.Controller;
import com.rudolfheszele.smsselector.controller.ControllerFactoryFactory;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class SmsSelectorMessageViewerActivity extends Activity implements View
{
	/**
     * Called when the activity is first created.
     * @param savedInstanceState The variable where the possible early state can be fetched from
     * */
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.smsselector_message_viewer_layout);
		mController = ControllerFactoryFactory.getControllerFactory().getController();
        mController.registerView(this);
        if(savedInstanceState != null)
        	mController.restoreState(getId(), savedInstanceState);
	}
	
	/**
     * Called just before the activity will be killed.
     * @param outState The variable the state will be saved to
     */
    @Override
    public void onSaveInstanceState(Bundle outState)
    {
    	mController.saveState(getId(), outState);
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
    	mController.buildMenu(this, menu, null);
    	
    	return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
    	return mController.menuClicked(this, item);
    }

	@Override
	public int getId()
	{
		return R.layout.smsselector_message_viewer_layout;
	}
	
	private Controller mController;
}
